package ahu.zdw.com;

import java.util.Arrays;
import java.util.Stack;

/**
 * Author zhangdongwei
 */
public class Test4 {
    public static void main(String[] args) {
        Solution solution = new Solution();
        boolean res = solution.isValid("[]{()[]}");
        System.out.println(res);
    }
    static class Solution {
        public boolean isValid(String s) {
            int l = s.length();
            if(l==0 || s.equals(null)){
                return true;
            }
            System.out.println(s);
            Stack<Character> stack = new Stack<Character>();
            for(int i=0; i<l; i++){
                char a = s.charAt(i);
                if(a=='('){
                    stack.push(')');
                    System.out.println(stack);
                }else if (a=='['){
                    stack.push(']');
                }else if (a=='{'){
                    stack.push('}');
                }else if(stack.isEmpty() || stack.pop()!=a){
                    return false;
                }
            }
            return stack.isEmpty();
        }
    }
}
